/**
 * 检测金额数字，将小数点前的数字转为有逗号‘,’分隔的数字并返回
 */
export function numberFormat(number) {
   var value = number.split(",").join('');
   var intPart = Number(value).toFixed(0); //获取整数部分
   var intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); //将整数部分逢三一断
   var floatPart = ".00"; //预定义小数部分
   var value2Array = value.split(".");
   //=2表示数据有小数位
   if(value2Array.length == 2) {
	   floatPart = value2Array[1].toString(); //拿到小数部分
	   return intPartFormat + "." + floatPart;
   } else {
	   return intPartFormat;
   }
};

/**
 * 将enter按键功能转换为tab按键功能
 */
export function enterToTab(e){
	if(e.keyCode == 13){
		var objlist = $("#pageinitccontainer").find("input");
		if(objlist.length == 0){
			console.log("id为pageinitccontainer的容器里面没有找到input标签！");
			return false;
		}
		var tabindex = $(e.target).attr('tabindex');
		var tabindex_target = null;
		if(tabindex == undefined){ 
			for(var i=0; i<objlist.length; i++){
				if(e.target == objlist[i]){
					$(objlist[i+1]).focus();
					tabindex_target = i;
					break;
				}
			}
			if(tabindex_target == objlist.length-1){
				$(objlist[0]).focus();
			}
		}else{
			var target = null;
			for(var i=0; i<objlist.length; i++){
				if(tabindex < $(objlist[i]).attr('tabindex')){
					if(null == tabindex_target){
						tabindex_target = $(objlist[i]).attr('tabindex');
						target = objlist[i];
					}else{
						if(tabindex_target > $(objlist[i]).attr('tabindex')){
							tabindex_target = $(objlist[i]).attr('tabindex');
							target = objlist[i];
						}
					}
				}
			}
			if($(target).attr('tabindex') == undefined){
				$(objlist[0]).focus();
			}else{
				$(target).focus();
			}
		}
	 }
}

/**
 * 反显数据公共方法
 * attr1 属性的key
 * attr2 属性的value
 */
export function transFormatter(attr1,attr2,targetDate,transList) {
	for(var i=0; i<transList.length; i++){
		if(targetDate == transList[i][attr1]){
			return transList[i][attr2];
		}
	}
};

